import Vue from "vue";
import VueRouter from "vue-router";

// 引入路由组件
import Home from "../pages/Home";
import Login from "../pages/Login";
import Music from "../pages/Home/Music";
import Play from "../pages/Home/Play";
import News from "../pages/Home/News";
// 使用vuerouter插件
Vue.use(VueRouter);

// 重写push
// 保留原始push
const oldPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (
  location,
  onComplete = () => {},
  onAbort = () => {}
) {
  oldPush.call(this, location, onComplete, onAbort);
};

// 3.创建路由对象
const router = new VueRouter({
  // 路由表配置
  routes: [
    {
      path: "/home",
      component: Home,
      name: "home",
      children: [
        {
          path: "music",
          component: Music,
          name: "music",
        },
        {
          path: "play",
          component: Play,
          name: "play",
        },
        {
          path: "news",
          component: News,
          name: "news",
        },
      ],
    },
    {
      path: "/login",
      component: Login,
      name: "login",
    },
    {
      path: "/",
      redirect: "/home",
    },
  ],
});
// 暴露路由对象
export default router;
